package cn.edu.xmu.orderpayment.payment.model.vo;

import cn.edu.xmu.oomall.core.model.VoObject;
import cn.edu.xmu.orderpayment.payment.model.po.PaymentPo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author  Guanlin Wang
 * @date  2021-11-12
 */

@Data
@NoArgsConstructor
public class PaymentVo implements VoObject {
    @ApiModelProperty(value = "支付id")
    private long id;

    @ApiModelProperty(value = "交易流水号")
    private String tradeSn;

    @ApiModelProperty(value = "支付渠道id")
    private Long patternId;

    @ApiModelProperty(value = "支付金额")
    private Long amount;

    @ApiModelProperty(value = "实际支付金额")
    private Long actualAmount;

    @ApiModelProperty(value = "单据id")
    private String documentId;

    @ApiModelProperty(value = "单据类型")
    private Byte documentType;//0 订单，1 保证金，2 订单订金， 3 订单尾款

    @ApiModelProperty(value = "实际支付时间")
    private LocalDateTime payTime;

    @ApiModelProperty(value = "开始支付时间")
    private LocalDateTime beginTime;

    @ApiModelProperty(value = "支付截止时间")
    private LocalDateTime endTime;

    @ApiModelProperty(value = "支付状态")
    private Byte state;

    @ApiModelProperty(value = "备注")
    private String descr;

    public SimpleAdminUser adjust;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private String adjustTime;//调账时间


    public SimpleAdminUser creator;//
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public LocalDateTime gmtCreate;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public LocalDateTime gmtModified;
    public SimpleAdminUser modifier;//adjust

    public PaymentPo createPo(){
        PaymentPo paymentPo = new PaymentPo();
        paymentPo.setTradeSn(tradeSn);
        paymentPo.setPatternId(patternId);
        paymentPo.setAmount(amount);
        paymentPo.setActualAmount(actualAmount);
        paymentPo.setDocumentId(documentId);
        paymentPo.setDocumentType(documentType);
        paymentPo.setPayTime(payTime);
        paymentPo.setBeginTime(beginTime);
        paymentPo.setEndTime(endTime);
        paymentPo.setState(state);
        paymentPo.setDescr(descr);
        return paymentPo;
    }

    public PaymentVo(PaymentPo paymentPo){
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        id = paymentPo.getId();
        tradeSn = paymentPo.getTradeSn();
        patternId = paymentPo.getPatternId();
        amount = paymentPo.getAmount();
        actualAmount = paymentPo.getActualAmount();
        documentId = paymentPo.getDocumentId();
        documentType = paymentPo.getDocumentType();
        beginTime = paymentPo.getBeginTime();
        endTime = paymentPo.getEndTime();
        state = paymentPo.getState();
        descr = paymentPo.getDescr();
        adjust =new SimpleAdminUser(paymentPo.getAdjustId(), paymentPo.getAdjustName());
        adjustTime = paymentPo.getAdjustName();
        creator = new SimpleAdminUser(paymentPo.getCreatorId(), paymentPo.getCreatorName());
        gmtCreate = paymentPo.getGmtCreate();
        gmtModified = paymentPo.getGmtModified();
        modifier = new SimpleAdminUser(paymentPo.getModifierId(), paymentPo.getModifierName());
    }

    @Override
    public Object createVo() {
        return this;
    }

    @Override
    public Object createSimpleVo() { return this; }

}
